package com.gluck.cases.app.biz.impl;

import com.gluck.cases.common.utils.enums.BizSerErrorEnum;
import com.gluck.cases.common.utils.utils.AssertUtil;
import com.gluck.cases.common.utils.utils.JwtUtil;
import com.gluck.cases.common.utils.utils.ShiroUsersUtil;
import com.gluck.cases.core.block.AdminUserBlock;
import com.gluck.cases.core.block.CommonBlock;
import com.gluck.cases.core.modal.assemble.AdminUserAssemble;
import com.gluck.cases.core.modal.constants.AuthConstants;
import com.gluck.cases.core.modal.dto.AdminUserDTO;
import com.gluck.cases.core.modal.entity.AdminUser;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

/**
 * @ClassName CommonService
 * @Desc service 基础类
 * @Author I am Gluck
 * @Date 2022/5/18 - 10:17 下午
 **/
public class BasecService {

    @Autowired
    private CommonBlock commonBlock;
    @Autowired
    private AdminUserBlock adminUserBlock;

    protected Map<String, String> queryPermissionField(String columns, String table, String conditions, String conditionsValue) {
        return commonBlock.queryPermissionField(columns, table, conditions, conditionsValue);
    }

    /**
     * 功能描述: 当前用户信息
     *
     * @Params []
     * @Return com.gluck.stock.oauth.core.modal.dto.AdminUserDTO
     * @Author I`m Gluck
     * @Date 2022/5/28
     */
    protected AdminUserDTO getUserInfo() {
        String userToken = ShiroUsersUtil.getUserToken();
        AssertUtil.isNull(userToken, BizSerErrorEnum.CUURENT_USER_NEED_LOGIN);
        String username = JwtUtil.getClaim(userToken, AuthConstants.USERNAME);
        AdminUser adminUser = adminUserBlock.queryByUsername(username);
        AssertUtil.isNull(adminUser, BizSerErrorEnum.SELECT_ERROR);
        return AdminUserAssemble.adminUserConvertAdminUserDTO(adminUser);
    }
}
